`
https://leetcode.cn/problems/linked-list-cycle-ii/
`

/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */

/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var detectCycle = function (head) {
  // 快慢指针
  let slow = head
  let fast = head
  let hasCircle = false
  while (fast && fast.next) {
    slow = slow.next
    fast = fast.next.next
    if (slow === fast) {
      hasCircle = true
      break
    }
  }
  if (!hasCircle) return null
  slow = head
  while (slow !== fast) {
    slow = slow.next
    fast = fast.next
  }
  return slow
};